<template>
  <el-dialog
    title="课程列表"
    :visible.sync="liveCourseVisible"
    :before-close="close"
    width="540px"
    top="calc((100vh - 436px) / 2)"
  >
    <div class="live-course-scrollbar">
      <el-scrollbar>
        <template v-if="!$util.isEmpty(liveCouresData)">
          <el-row
            type="flex"
            align="middle"
            class="live-course"
            v-for="(item, index) in liveCouresData"
            :key="index"
          >
            <div class="picture">
              <edu-image :src="item.cover_url"></edu-image>
              <span class="tag" :class="courseTypeClass[item.course_type]">{{
                item.course_type_text
              }}</span>
            </div>
            <el-row type="flex" justify="space-between" class="desc">
              <div class="title">{{ item.title }}</div>
              <div class="price">
                {{ item.price | formatMoney }}
              </div>
            </el-row>
            <el-button type="primary" size="small" @click="handleNext(item.id)">去抢购</el-button>
          </el-row>
        </template>
        <EduNoData :image="false" text="暂时没有带货课程哦~" v-else></EduNoData>
      </el-scrollbar>
    </div>
  </el-dialog>
</template>

<script>
import EduNoData from '@/components/EduNoData'
import { mapState } from 'vuex'
export default {
  components: {
    EduNoData
  },
  data() {
    return {
      courseTypeClass: {
        1: 'video',
        2: 'live',
        3: 'multipart',
        4: 'classes'
      },
      liveCouresData: []
    }
  },
  computed: {
    ...mapState('live', {
      liveCourseVisible: state => state.liveCourseDialogVisible
    }),
    ...mapState({
      getCurrentPlayItem: state => state.course.currentPlayItem
    })
  },
  created() {
    // 带货课程
    this.$api.getLiveCourse(
      {
        section_id: this.getCurrentPlayItem.id
      },
      res => {
        const { data } = res
        this.liveCouresData = data
      }
    )
  },
  methods: {
    close() {
      this.$store.commit('live/CourseDialogVisible', false)
    },
    handleNext(id) {
      const { href } = this.$router.resolve({ path: '/course/' + id })
      window.open(href, '_blank')
    }
  }
}
</script>

<style lang="scss" scoped>
.live-course-scrollbar {
  height: 322px;
  margin-right: -17px;
  ::v-deep .el-scrollbar {
    height: 100%;
    .el-scrollbar__wrap {
      overflow-x: auto;
    }
  }
}

.live-course {
  margin-bottom: 20px;
  padding-right: 17px;
  .picture {
    height: 0;
    width: 170px;
    position: relative;
    padding-top: 94px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    .el-image {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }
    .tag {
      font-size: 12px;
      font-weight: 400;
      text-align: center;
      color: white;
      width: 46px;
      height: 22px;
      line-height: 22px;
      box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.08);
      border-radius: 20px 0px 0px 20px;
      position: absolute;
      right: 0;
      top: 15px;
      &.video {
        background-color: #ff8a8a;
      }
      &.live {
        background-color: #67c23a;
      }
      &.multipart {
        background-color: #80ccff;
      }
      &.classes {
        background-color: #ff8a52;
      }
    }
  }
  .desc {
    height: 94px;
    flex: 1;
    padding: 5px 0;
    flex-direction: column;
    margin: 0 34px 0 13px;
  }
  .title {
    width: 215px;
    font-size: 16px;
    font-weight: 400;
    color: #303133;
    line-height: 24px;
    @include ellipsis();
  }
  .price {
    font-size: 16px;
    font-weight: 500;
    color: $text-color-price;
  }
}
</style>
